package com.tim.app.ui.activity.person_center;

import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.TextView;

import com.application.library.runtime.event.EventListener;
import com.application.library.runtime.event.EventManager;
import com.application.library.widget.smarttab.SmartTabLayout;
import com.tim.app.R;
import com.tim.app.constant.EventTag;
import com.tim.app.server.logic.UserManager;
import com.tim.app.ui.activity.BaseActivity;
import com.tim.app.ui.adapter.TabAdapter;
import com.tim.app.ui.fragment.person.InvateFriendFragment;
import com.tim.app.ui.fragment.person.MyFollowTopicFragment;
import com.tim.app.ui.fragment.person.MyInvateFragment;


/**
 * 邀请红包
 */
public class InvateRedbagActivity extends BaseActivity {
    private ImageButton ibBack;

    private SmartTabLayout tab_layout;
    private ViewPager vpMyViewContent;
    private TabAdapter pageAdapter;
    private TextView tv_edit_invatecode;


    public static void start(Context context) {
        Intent intent = new Intent(context, InvateRedbagActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_invate_redbag;
    }


    @Override
    public void initView() {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        ibBack = (ImageButton) findViewById(R.id.ibBack);
        tab_layout = (SmartTabLayout) findViewById(R.id.tab_layout);
        vpMyViewContent = (ViewPager) findViewById(R.id.vpMyViewContent);
        tv_edit_invatecode = (TextView) findViewById(R.id.tv_edit_invatecode);
        pageAdapter = new TabAdapter(getSupportFragmentManager());
        pageAdapter.addFragment(new InvateFriendFragment(), getString(R.string.invate_friend));
        pageAdapter.addFragment(new MyInvateFragment(), getString(R.string.my_invate));
        vpMyViewContent.setOffscreenPageLimit(2);
        vpMyViewContent.setAdapter(pageAdapter);
        vpMyViewContent.setCurrentItem(0);
        tab_layout.setViewPager(vpMyViewContent);
        //   EventManager.ins().registListener(EventTag.INPUTINVATECODE, listener);
    }

//    private EventListener listener = new EventListener() {
//        @Override
//        public void handleMessage(int what, int arg1, int arg2, Object dataobj) {
//            tv_edit_invatecode.setVisibility(View.GONE);
//        }
//    };

    @Override
    public void initData() {
        ibBack.setOnClickListener(this);
        tv_edit_invatecode.setOnClickListener(this);
//        if (!TextUtils.isEmpty(UserManager.ins().getLoginUser().getInviteUuid())) {
//            tv_edit_invatecode.setVisibility(View.GONE);
//        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (!TextUtils.isEmpty(UserManager.ins().getLoginUser().getInviteUuid())) {
            tv_edit_invatecode.setVisibility(View.GONE);
        }
    }


    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //  EventManager.ins().removeListener(EventTag.INPUTINVATECODE, listener);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ibBack://返回
                finish();
                break;
            case R.id.tv_edit_invatecode:
                InputInvateCodeActivity.start(this);
                break;
        }
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    }

}
